package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.qiantu.phone.BuildConfig;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.bean.AddDeviceBean;
import com.qiantu.phone.glide.GlideApp;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/09/22
 *    desc   : 状态数据列表
 */
public final class AddDeviceAdapter extends AppAdapter<AddDeviceBean.DeviceConfigNetworkBean> {

    public AddDeviceAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView iconDevice;
        private final TextView tvDeviceName;

        private ViewHolder() {
            super(R.layout.item_add_device);
            iconDevice = findViewById(R.id.device_icon);
            tvDeviceName = findViewById(R.id.tv_device_name);
        }

        @Override
        public void onBindView(int position) {
            AddDeviceBean.DeviceConfigNetworkBean item = getItem(position);
            GlideApp.with(iconDevice).load(BuildConfig.APP_IMAGE_BASE +"app/images/icon/"+ item.getProductInfo().getLogo()).into(iconDevice);
            tvDeviceName.setText(item.getProductInfo().getName());
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}